package com.jdz.gxq.info.admin.file.service;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

import com.jdz.gxq.info.admin.file.bo.ImageInfo;
import com.jdz.gxq.info.common.utils.FileUtils;

public class FileServiceImpl implements FileService {

	private QueryDAO queryDAO = null;

	private UpdateDAO updateDAO = null;

	public void insertImageInfo(ImageInfo imageInfo) {

		updateDAO.execute("file.insertImageInfo", imageInfo);
	}
	
	public ImageInfo getImageInfo(String picId) {

		return queryDAO.executeForObject("file.getImageInfoById", picId, ImageInfo.class);
	}
	
	/**
	 * 删除图片信息（包括数据库中信息和物理路径上的图片)
	 */
	public void deleteImageInfo(String picId, String realPath) {
		
		ImageInfo imageInfo = getImageInfo(picId);
		
		if (imageInfo == null) {
			return;
		}
		
		updateDAO.execute("file.delImageInfoById", picId);
		
		// 删除图片文件
		FileUtils.deleteFile(realPath + "\\" + imageInfo.getPictureName());
	}

	public void setQueryDAO(QueryDAO queryDAO) {
		this.queryDAO = queryDAO;
	}

	public void setUpdateDAO(UpdateDAO updateDAO) {
		this.updateDAO = updateDAO;
	}
}
